/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.audit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.audit.AuditException;
import ch.qos.logback.audit.client.AuditorFacade;
import ch.qos.logback.audit.client.AuditorFactory;

/**
 * Class for auditing elements
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 *
 */
public class Audit {

	private static final Audit instance = new Audit();
	private static final Logger LOG = LoggerFactory.getLogger(Audit.class);
	
	/**
	 * Private constructor
	 */
	private Audit(){
		 try {
			AuditorFactory.setApplicationName("BabyStep");
		} catch (AuditException e) {
			
		}
	}
	
	/**
	 * Audit to appenders. Logs to error if no audit appender available
	 * @param subject
	 * @param verb
	 * @param object
	 */
	public void audit(String subject, String verb, String object){
		try {
			new AuditorFacade(subject, verb, object).audit();
		} catch (AuditException e) {
			LOG.error("Error auditing:", e);
		}
	}

	/**
	 * Audit to appenders. Throws error if no appenders available
	 * @param subject
	 * @param verb
	 * @param object
	 * @throws AuditException
	 */
	public void auditCritical(String subject, String verb, String object) throws AuditException{
			new AuditorFacade(subject, verb, object).audit();
	}
	
	/**
	 * @return the instance
	 */
	public static Audit getInstance() {
		return instance;
	}
}
